#pragma once

#include<iostream>
#include<sys/epoll.h>
#include<unistd.h>



class Epoller
{
public:
    Epoller():_epfd(epoll_create(128))
    {}

    void AddEvents(int _sockfd,uint32_t _events)
    {
        struct epoll_event _event;
        _event.data.fd = _sockfd;
        _event.events = _events;
        int n = epoll_ctl(_epfd,EPOLL_CTL_ADD,_sockfd,&_event);
        if(n < 0)
        {
            return;
        }
    }

    int Wait(struct epoll_event revs[],int timeout,int size)
    {
        int n = epoll_wait(_epfd,revs,size,timeout);
        return n;
    }



    ~Epoller()
    {
        if(_epfd >= 0)
            close(_epfd);
    }


private:
    int _epfd;
};